//
//  MyOrderViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/23.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "MyOrderViewController.h"

#import "MyOrderCell.h"
#import "OrderDetCell.h"
#import "OrderDetViewController.h"
#import "AllClassifyView.h"
#import "CompletionStatusView.h"
#import "OrderTimeView.h"

#import "AllClassIfyModel.h"
#import "RentalDetailsViewController.h"
#import "CarBuyingDetailsViewController.h"
#import "DryCleaningViewController.h"
#import "CoolyViewController.h"
#import "OrderCommentViewController.h"      //评论
#import "MyOrderModel.h"
#import "MJExtension.h"
@interface MyOrderViewController ()<UITableViewDelegate,UITableViewDataSource>{
    UILabel *labLine;
    UIButton *btnL;
    UIButton *btnR;
}

@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableDictionary *dic;

@property (nonatomic, strong) AllClassifyView *allcalssView;

@property (nonatomic, strong) CompletionStatusView *statusView;

@property (nonatomic, strong) OrderTimeView *orderTimeView;

//==========DATA

@property (nonatomic, strong) NSString *typeId;

@property (nonatomic, strong) NSString *timeStatus;

@property (nonatomic, strong) NSString *status;

@property (nonatomic, strong) NSMutableArray *orderArray;

@property (nonatomic, assign) NSInteger orderPage;

@property (nonatomic, strong) NSMutableArray *transactionArray;

@property (nonatomic, assign) NSInteger orderTransactionPage;

@property (nonatomic, strong) NSString *orderDetailedType;//交易类型 2为增加、3为减少
@property (nonatomic, strong)NSMutableArray *modelArr;
@end

@implementation MyOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setBGColor];
    _dic = [NSMutableDictionary dictionary];
    
    [self loadNav];
    [self loadUI];
    
    [self setupView];
    
    self.orderPage = 1;
    
    [self loadData];
    
    self.orderTransactionPage = 1;
    
    self.orderDetailedType = @"3";
    
//    [self loadOrderDetailedData];
}
/*
 装请求数据的模型数组
 */
-(NSMutableArray *)modelArr
{
    if (!_modelArr) {
        
        _modelArr = [NSMutableArray array];
    }
    return _modelArr;
}

//自定义导航栏
- (void)loadNav{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
    view.backgroundColor = [UIColor whiteColor];
    view.userInteractionEnabled = YES;
    [self.view addSubview:view];
    //返回按钮
    UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnBack setImage:[UIImage imageNamed:@"箭头"] forState:UIControlStateNormal];
    [btnBack addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btnBack];
    [btnBack makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.left);
        make.bottom.equalTo(view.bottom);
        make.width.height.equalTo(40);
    }];
    
    btnL = [UIButton buttonWithType:UIButtonTypeCustom];
    //btnL.backgroundColor = [UIColor grayColor];
    btnL.frame = CGRectMake(ScreenWidth/2-75, 30, 65, 25);
    [btnL setTitle:@"我的订单" forState:UIControlStateNormal];
    [btnL setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btnL.titleLabel.font = [UIFont systemFontOfSize:15.0];
    [btnL addTarget:self action:@selector(clickL) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btnL];
    
    btnR = [UIButton buttonWithType:UIButtonTypeCustom];
    //btnR.backgroundColor = [UIColor orangeColor];
    btnR.frame = CGRectMake(ScreenWidth/2+10, 30, 65, 25);
    [btnR setTitle:@"交易明细" forState:UIControlStateNormal];
    [btnR setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btnR.titleLabel.font = [UIFont systemFontOfSize:15.0];
    [btnR addTarget:self action:@selector(clickR) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btnR];
    
    labLine = [[UILabel alloc] initWithFrame:CGRectMake(btnL.frame.origin.x+18, 60, 30, 4)];
    labLine.backgroundColor = [UIColor redColor];
    labLine.layer.cornerRadius = 10.0;
    [view addSubview:labLine];
    
    UILabel *labL = [[UILabel alloc] initWithFrame:CGRectMake(0, 63.5, ScreenWidth, 0.5)];
    labL.backgroundColor = COLOR_RGB(217, 217, 217, 1);
    [view addSubview:labL];
    
}

- (void)setupView{
    self.allcalssView = [[AllClassifyView alloc]init];
    [self.allcalssView setHidden:YES];
    [self.view addSubview:self.allcalssView];
    __weak typeof(self) weakSelf = self;
    self.allcalssView.cancelAction = ^{
        [weakSelf.allcalssView setHidden:YES];
        UIButton *oneButton = [weakSelf.view viewWithTag:10086];
        [oneButton setSelected:NO];
    };
    
    self.allcalssView.selectAction = ^(AllClassIfyModel *model) {
        [weakSelf.allcalssView setHidden:YES];
        weakSelf.typeId = model.value;
        if ([model.value isEqualToString:@"0"]) {
            weakSelf.typeId = @"";
        }
        
        [weakSelf loadData];
    };
    
    [self.allcalssView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(104);
        make.left.equalTo(0);
        make.right.equalTo(0);
        make.bottom.equalTo(0);
    }];
    
    self.statusView = [[CompletionStatusView alloc]init];
    [self.statusView setHidden:YES];
    [self.view addSubview:self.statusView];
    
    self.statusView.cancelAction = ^{
        [weakSelf.statusView setHidden:YES];
        UIButton *oneButton = [weakSelf.view viewWithTag:10087];
        [oneButton setSelected:NO];
    };
    
    self.statusView.selectAction = ^(AllClassIfyModel *model) {
        [weakSelf.statusView setHidden:YES];
        weakSelf.status = model.value;
        if ([model.value isEqualToString:@"0"]) {
            weakSelf.status = @"";
        }

        [weakSelf loadData];
    };
    
    [self.statusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(104);
        make.left.equalTo(0);
        make.right.equalTo(0);
        make.bottom.equalTo(0);
    }];
    
    self.orderTimeView = [[OrderTimeView alloc]init];
    [self.orderTimeView setHidden:YES];
    [self.view addSubview:self.orderTimeView];
    
    self.orderTimeView.cancelAction = ^{
        [weakSelf.orderTimeView setHidden:YES];
        UIButton *oneButton = [weakSelf.view viewWithTag:10088];
        [oneButton setSelected:NO];
    };
    
    self.orderTimeView.selectAction = ^(AllClassIfyModel *model) {
        [weakSelf.orderTimeView setHidden:YES];
        weakSelf.timeStatus = model.value;
        if ([model.value isEqualToString:@"0"]) {
            weakSelf.timeStatus = @"";
        }
        
        [weakSelf loadData];
    };
    
    [self.orderTimeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(104);
        make.left.equalTo(0);
        make.right.equalTo(0);
        make.bottom.equalTo(0);
    }];
}

- (void)clickBack{
    [self.navigationController popViewControllerAnimated:YES];
}
//交易明细
- (void)clickL{
    [UIView animateWithDuration:0.3 animations:^{
        labLine.frame = CGRectMake(btnL.frame.origin.x+18, 60, 30, 4);
    }];
    [_dic setObject:@"aaa" forKey:@"tag"];
    self.orderPage = 1;
    
    [self loadData];
}
//我的订单
- (void)clickR{
    [UIView animateWithDuration:0.3 animations:^{
        labLine.frame = CGRectMake(btnR.frame.origin.x+18, 60, 30, 4);
    }];
    [_dic setObject:@"sss" forKey:@"tag"];
    self.orderTransactionPage = 1;
    
    [self loadOrderDetailedData];
}

- (void)loadUI{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    //去分割线
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableView];
    
    [_dic setObject:@"aaa" forKey:@"tag"];
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        NSString *str = [self.dic objectForKey:@"tag"];
        if ([str isEqualToString:@"aaa"]) {
            self.orderPage = 1;
            
            [self loadData];
        }else{
            self.orderTransactionPage = 1;
            
            [self loadOrderDetailedData];
        }
    }];
    
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        NSString *str = [self.dic objectForKey:@"tag"];
        if ([str isEqualToString:@"aaa"]) {
            self.orderPage ++;
            
            [self loadData];
        }else{
            self.orderTransactionPage ++;
            
            [self loadOrderDetailedData];
        }
    }];
}

#pragma -mark UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
     NSString *str = [_dic objectForKey:@"tag"];
    if ([str isEqualToString:@"aaa"]) {
        return self.orderArray.count;
    }else{
        return self.transactionArray.count;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *str = [_dic objectForKey:@"tag"];
    
    if ([str isEqualToString:@"aaa"]) {
        static NSString* cellIdentity = @"MyOrderCell";
        MyOrderCell* cell = [MyOrderCell initTableViewCell:tableView andCellIdentify:cellIdentity];
        cell.btnCancel.tag  = cell.callBtn.tag = indexPath.row;
        
//        static NSString *cellId = @"Cell1";
//        [tableView registerNib:[UINib nibWithNibName:@"MyOrderCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:cellId];
//        MyOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
//        if (!cell) {
//            cell = [[[NSBundle mainBundle] loadNibNamed:@"MyOrderCell" owner:nil options:nil] lastObject];
//        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
//        cell.btnFinish.layer.borderWidth = 0.5;
//        cell.btnFinish.layer.borderColor = [UIColor redColor].CGColor;
//
//        cell.btnReset.layer.borderWidth = 0.5;
//        cell.btnReset.layer.borderColor = [UIColor redColor].CGColor;
//
//        cell.evaluationBtn.layer.borderWidth = 0.5;
//        cell.evaluationBtn.layer.borderColor = [UIColor redColor].CGColor;
        
        cell.btnCancel.layer.borderWidth = 0.5;
        cell.btnCancel.layer.borderColor = [UIColor redColor].CGColor;
//        [cell.btnCancel addTarget:self action:@selector(cancelBtn:) forControlEvents:UIControlEventTouchUpInside];
        
        NSDictionary *itemdic = [self.orderArray objectAtIndex:indexPath.row];
        [cell setOrderData:itemdic];
        cell.cancelActionButton = ^(UIButton *sender)
        {
            [self cancelOrderEvent:itemdic btn:sender];
        };
        
        return cell;
    }else{
        static NSString *cellId = @"Cell2";
        OrderDetCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"OrderDetCell" owner:nil options:nil] lastObject];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        NSDictionary *itemdic = [self.transactionArray objectAtIndex:indexPath.row];
        [cell setOrderDetData:itemdic];
        return cell;
    }
    
}
//行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *str = [_dic objectForKey:@"tag"];
    
    if ([str isEqualToString:@"aaa"]) {
        return 135.0;
    }else{
        return 60.0;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *str = [_dic objectForKey:@"tag"];
    if ([str isEqualToString:@"aaa"]) {
        NSDictionary *itemdic = [self.orderArray objectAtIndex:indexPath.row];
        NSInteger typeId = [[itemdic objectForKey:@"typeid"] integerValue];
        if (typeId == 3 || typeId == 2 || typeId == 9) {
            RentalDetailsViewController *zhu = [[RentalDetailsViewController alloc]init];
            zhu.detailsDic = itemdic;
            [self.navigationController pushViewController:zhu animated:YES];
        }
        if (typeId == 11 || typeId == 12 || typeId == 13 || typeId == 7 || typeId == 8 || typeId == 4) {
            CarBuyingDetailsViewController *car = [[CarBuyingDetailsViewController alloc]init];
            car.detailsDic = itemdic;
            [self.navigationController pushViewController:car animated:YES];
        }
        if (typeId == 1 || typeId == 10) {
            DryCleaningViewController *dry = [[DryCleaningViewController alloc]init];
            dry.detailsDic = itemdic;
            [self.navigationController pushViewController:dry animated:YES];
        }
        if (typeId == 14) {
            
        }
        /*
        if (typeId == 4) {
            CoolyViewController *cool = [[CoolyViewController alloc]init];
            cool.detailsDic = itemdic;
            [self.navigationController pushViewController:cool animated:YES];
        }*/
        
    }else{
        OrderDetViewController *det = [[OrderDetViewController alloc] init];
        NSDictionary *itemdic = [self.transactionArray objectAtIndex:indexPath.row];
        det.transactionDic = itemdic;
        [self.navigationController pushViewController:det animated:YES];
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40.0)];
    headView.backgroundColor = [UIColor whiteColor];
    
    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 39, ScreenWidth, 1)];
    lab.backgroundColor = COLOR_RGB(242, 242, 242, 0.5);
    [headView addSubview:lab];
    
    NSArray *array = @[@"全部分类",@"完成状态",@"下单时间"];
    NSString *str = [_dic objectForKey:@"tag"];
    if ([str isEqualToString:@"aaa"]) {
        
        for (NSInteger i = 0; i<array.count; i++) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(ScreenWidth/3*i, 0, ScreenWidth/3, 40.0);
            btn.titleLabel.font = [UIFont systemFontOfSize:14.0];
            [btn setTitle:[NSString stringWithFormat:@"%@",array[i]] forState:UIControlStateNormal];
            [btn setTitleColor:COLOR_RGB(77, 77, 77, 1) forState:UIControlStateNormal];
            [btn setTitleColor:HexColorInt32_t(FD1142) forState:UIControlStateSelected];
            [btn setImage:[UIImage imageNamed:@"多边形-2"] forState:UIControlStateNormal];
            [btn setImage:[UIImage imageNamed:@"多边形-3"] forState:UIControlStateSelected];
            [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btn.imageView.frame.size.width, 0, btn.imageView.frame.size.width)];
            [btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.frame.size.width+5, 0, -btn.titleLabel.frame.size.width)];
            btn.tag = i + 10086;
            [btn addTarget:self action:@selector(clicks:) forControlEvents:UIControlEventTouchUpInside];
            [headView addSubview:btn];
        }
        
    }else{
        UIButton *btnAll = [UIButton buttonWithType:UIButtonTypeCustom];
        btnAll.frame = CGRectMake(0, 0, ScreenWidth, 40.0);
        [btnAll setTitle:@"全部明细" forState:UIControlStateNormal];
        [btnAll setTitleColor:COLOR_RGB(77, 77, 77, 1) forState:UIControlStateNormal];
        btnAll.titleLabel.font = [UIFont systemFontOfSize:14.0];
        if ([self.orderDetailedType isEqualToString:@"2"]){
            [btnAll setImage:[UIImage imageNamed:@"多边形-3"] forState:UIControlStateNormal];
        }else{
            [btnAll setImage:[UIImage imageNamed:@"多边形-2"] forState:UIControlStateNormal];
        }
        [btnAll setTitleEdgeInsets:UIEdgeInsetsMake(0, -btnAll.imageView.frame.size.width, 0, btnAll.imageView.frame.size.width)];
        [btnAll setImageEdgeInsets:UIEdgeInsetsMake(0, btnAll.titleLabel.frame.size.width+5, 0, -btnAll.titleLabel.frame.size.width)];
        [btnAll addTarget:self action:@selector(orderAllEvent:) forControlEvents:UIControlEventTouchUpInside];
        [headView addSubview:btnAll];
    }
    
    return headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40.0;
}

- (void)clicks:(UIButton *)btn{
    [btn setSelected:!btn.selected];
    NSInteger tag = btn.tag;
    if (tag == 10086) {
        if (btn.selected == YES) {
            [self.allcalssView setHidden:NO];
            [self.statusView setHidden:YES];
            [self.orderTimeView setHidden:YES];
            UIButton *one = [self.view viewWithTag:10087];
            UIButton *two = [self.view viewWithTag:10088];
            [one setSelected:NO];
            [two setSelected:NO];
        }else{
            [self.allcalssView setHidden:YES];
        }
        
    }
    
    if (tag == 10087) {
        if (btn.selected == YES) {
            [self.statusView setHidden:NO];
            [self.allcalssView setHidden:YES];
            [self.orderTimeView setHidden:YES];
            UIButton *one = [self.view viewWithTag:10086];
            UIButton *two = [self.view viewWithTag:10088];
            [one setSelected:NO];
            [two setSelected:NO];
        }else{
            [self.statusView setHidden:YES];
        }
    }
    
    if (tag == 10088) {
        if (btn.selected == YES) {
            [self.orderTimeView setHidden:NO];
            [self.allcalssView setHidden:YES];
            [self.statusView setHidden:YES];
            UIButton *one = [self.view viewWithTag:10086];
            UIButton *two = [self.view viewWithTag:10087];
            [one setSelected:NO];
            [two setSelected:NO];
        }else{
            [self.orderTimeView setHidden:YES];
        }
    }
}
//
- (void)orderAllEvent:(UIButton *)sender{
    self.orderTransactionPage = 1;
    NSLog(@"orderDetailedType:%@",self.orderDetailedType);
    if ([self.orderDetailedType isEqualToString:@"2"]) {
        self.orderDetailedType = @"3";
        [self loadOrderDetailedData];
    }else{
        self.orderDetailedType = @"2";
        [self loadOrderDetailedData];
    }
}

- (void)loadData{
    [SVProgressHUD showWithStatus:@"加载中"];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setValue:token forKey:@"verifyToken"];
    [parmas setValue:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setValue:self.typeId forKey:@"typeid"];
    [parmas setValue:self.timeStatus forKey:@"timeStatus"];
    [parmas setValue:self.status forKey:@"status"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/UserOrder/index/p/%zd",urlHead,self.orderPage];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"用户查看订单列表res:%@",responseObject);
        NSInteger state = [[responseObject objectForKey:@"status"] integerValue];
        NSString *msg = [responseObject objectForKey:@"msg"];
        NSArray *dataArray = [responseObject objectForKey:@"content"];
        if (state  == 200 ) {
            if ([dataArray isKindOfClass:[NSArray class]] && dataArray.count > 0) {
                //字典数组转模型数组
                self.modelArr = [MyOrderModel mj_objectArrayWithKeyValuesArray:responseObject[@"content"]];
                
                if (self.orderPage == 1) {
                    _orderArray = [dataArray mutableCopy];
                }else{
                    [_orderArray addObjectsFromArray:dataArray];
                }
                if (dataArray.count < 10) {
                    [self.tableView.mj_footer endRefreshingWithNoMoreData];
                }
                [self.tableView reloadData];
            }
            [SVProgressHUD dismiss];
        }else{
            [SVProgressHUD dismiss];
            [LICGToast showWithText:msg];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}
//用户交易详情
- (void)loadOrderDetailedData{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setValue:token forKey:@"verifyToken"];
    [parmas setValue:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setValue:self.orderDetailedType forKey:@"type"];
    NSLog(@"parmas:%@",parmas);
    NSString *url = [NSString stringWithFormat:@"%@/App/UserOrder/TransactionDetails/p/%zd",urlHead,self.orderTransactionPage];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"用户查看订单明细res:%@",responseObject);
        NSInteger state = [[responseObject objectForKey:@"status"] integerValue];
        NSString *msg = [responseObject objectForKey:@"msg"];
        NSArray *dataArray = [responseObject objectForKey:@"content"];
        if (state  == 200 ) {
            if ([dataArray isKindOfClass:[NSArray class]] && dataArray.count > 0) {
                if (self.orderTransactionPage == 1) {
                    self.transactionArray = [dataArray mutableCopy];
                    
                }else{
                    [self.transactionArray addObjectsFromArray:dataArray];
                }
                
                if (dataArray.count < 10) {
                    [self.tableView.mj_footer endRefreshingWithNoMoreData];
                }
                
                [self.tableView reloadData];
            }
            [SVProgressHUD dismiss];
        }else{
            [SVProgressHUD dismiss];
            [LICGToast showWithText:msg];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}

- (NSMutableArray *)orderArray{
    if (!_orderArray) {
        _orderArray = [[NSMutableArray alloc]init];
    }
    return _orderArray;
}

// 取消订单
#pragma mark ---  取消订单、评论点击；已评论不用点击
- (void)cancelOrderEvent:(NSDictionary *)itemDic btn:(UIButton *)btn{
    
    NSInteger typeidIndex = [[itemDic objectForKey:@"typeid"] integerValue];
    NSString *orderId = [itemDic objectForKey:@"id"];
    NSString *iscommentStr = [itemDic objectForKey:@"iscomment"];
    
    if ([btn.currentTitle containsString:@"评价"]){
        //未评价
        if ([iscommentStr isEqualToString:@"3"]) {
            OrderCommentViewController *commentVC = [OrderCommentViewController new];
            commentVC.model = self.modelArr[btn.tag];
            [self.navigationController pushViewController:commentVC animated:YES];
            return;
        }if ([iscommentStr isEqualToString:@"2"]) {
            return;
        }
    }else
    {
    
    //苦力
    if (typeidIndex == 4) {
        [self coolyCancelOrder:orderId urlString:@"App/UserOrder/abolitionOfCooliesOrders"];
    }
    //干洗
    if (typeidIndex == 1) {
        [self coolyCancelOrder:orderId urlString:@"App/UserOrder/cancelDryCleaningOrder"];
    }
    //家政
    if (typeidIndex == 7) {
        [self coolyCancelOrder:orderId urlString:@"App/UserOrder/CancellationOfDomesticOrders"];
    }
    //开锁
    if (typeidIndex == 8) {
        [self coolyCancelOrder:orderId urlString:@"App/UserOrder/cancelUnlockOrder"];
    }
    //蔬果
    if (typeidIndex == 10) {
        [self coolyCancelOrder:orderId urlString:@"App/UserOrder/cancelVegetableOrder"];
    }
    //洗车
    if (typeidIndex == 12) {
        [self coolyCancelOrder:orderId urlString:@"App/UserOrder/cancelCarWashingOrder"];
    }
    //快递
    if (typeidIndex == 6) {
        [self coolyCancelOrder:orderId urlString:@"App/UserOrder/cancellationOfExpressOrder"];
    }
//    //同城快递
//    if (typeidIndex == ) {
//        [self coolyCancelOrder:orderId urlString:@"App/UserOrder/cancelCityExpress"];
//    }
    
    if (typeidIndex == 14) {
        [self coolyCancelOrder:orderId urlString:@"App/UserOrder/theUserCanceledOrders"];
      }
    }
}

- (void)reolodOrderListData{
    self.orderPage = 1;
    [self loadData];
}

//苦力取消订单

- (void)coolyCancelOrder:(NSString *)orderId urlString:(NSString *)urlString{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setValue:token forKey:@"verifyToken"];
    [parmas setValue:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setValue:orderId forKey:@"orderid"];
    
    NSString *url = [NSString stringWithFormat:@"%@/%@",urlHead,urlString];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
       
        [SVProgressHUD dismiss];
        NSLog(@"取消苦力订单res:%@",responseObject);
        NSInteger state = [[responseObject objectForKey:@"status"] integerValue];
        NSString *msg = [responseObject objectForKey:@"msg"];
        if (state  == 200 ) {
            [LICGToast showWithText:msg];
            [self reolodOrderListData];
        }else{
            [LICGToast showWithText:msg];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
